package org.com.star.event.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.com.star.event.service.UserService;
import org.com.star.event.service.event.UserEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

/**
 * 实现事件发布接口，将需要的事件进行发布
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService, ApplicationEventPublisherAware {

    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void register(String username) {
        log.info("注册用户名: {}", username);
        // 发布事件
        applicationEventPublisher.publishEvent(new UserEvent(this, username));
    }

}
